using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
	/// <summary>
	/// Strongly-typed collection for the HierarchicalRule class.
	/// </summary>
	[Serializable]
	public partial class HierarchicalRuleCollection : ActiveList<HierarchicalRule,HierarchicalRuleCollection> 
	{	   
		public HierarchicalRuleCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_HierarchicalRule table.
	/// </summary>
	[Serializable]
	public partial class HierarchicalRule : ActiveRecord<HierarchicalRule>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public HierarchicalRule()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public HierarchicalRule(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public HierarchicalRule(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public HierarchicalRule(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_HierarchicalRule", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarHierarchicalRuleId = new TableSchema.TableColumn(schema);
				colvarHierarchicalRuleId.ColumnName = "HierarchicalRuleId";
				colvarHierarchicalRuleId.DataType = DbType.Guid;
				colvarHierarchicalRuleId.MaxLength = 0;
				colvarHierarchicalRuleId.AutoIncrement = false;
				colvarHierarchicalRuleId.IsNullable = false;
				colvarHierarchicalRuleId.IsPrimaryKey = true;
				colvarHierarchicalRuleId.IsForeignKey = false;
				colvarHierarchicalRuleId.IsReadOnly = false;
				colvarHierarchicalRuleId.DefaultSetting = @"";
				colvarHierarchicalRuleId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHierarchicalRuleId);
				
				TableSchema.TableColumn colvarTypeId = new TableSchema.TableColumn(schema);
				colvarTypeId.ColumnName = "TypeId";
				colvarTypeId.DataType = DbType.Guid;
				colvarTypeId.MaxLength = 0;
				colvarTypeId.AutoIncrement = false;
				colvarTypeId.IsNullable = false;
				colvarTypeId.IsPrimaryKey = false;
				colvarTypeId.IsForeignKey = true;
				colvarTypeId.IsReadOnly = false;
				colvarTypeId.DefaultSetting = @"";
				
					colvarTypeId.ForeignKeyTableName = "medianamik_Type";
				schema.Columns.Add(colvarTypeId);
				
				TableSchema.TableColumn colvarParentTypeId = new TableSchema.TableColumn(schema);
				colvarParentTypeId.ColumnName = "ParentTypeId";
				colvarParentTypeId.DataType = DbType.Guid;
				colvarParentTypeId.MaxLength = 0;
				colvarParentTypeId.AutoIncrement = false;
				colvarParentTypeId.IsNullable = true;
				colvarParentTypeId.IsPrimaryKey = false;
				colvarParentTypeId.IsForeignKey = true;
				colvarParentTypeId.IsReadOnly = false;
				colvarParentTypeId.DefaultSetting = @"";
				
					colvarParentTypeId.ForeignKeyTableName = "medianamik_Type";
				schema.Columns.Add(colvarParentTypeId);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_HierarchicalRule",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("HierarchicalRuleId")]
		public Guid HierarchicalRuleId 
		{
			get { return GetColumnValue<Guid>(Columns.HierarchicalRuleId); }

			set { SetColumnValue(Columns.HierarchicalRuleId, value); }

		}

		  
		[XmlAttribute("TypeId")]
		public Guid TypeId 
		{
			get { return GetColumnValue<Guid>(Columns.TypeId); }

			set { SetColumnValue(Columns.TypeId, value); }

		}

		  
		[XmlAttribute("ParentTypeId")]
		public Guid? ParentTypeId 
		{
			get { return GetColumnValue<Guid?>(Columns.ParentTypeId); }

			set { SetColumnValue(Columns.ParentTypeId, value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Type ActiveRecord object related to this HierarchicalRule
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.Type Type
		{
			get { return Medianamik.SubsonicDALProvider.DAL.Type.FetchByID(this.TypeId); }

			set { SetColumnValue("TypeId", value.TypeId); }

		}

		
		
		/// <summary>
		/// Returns a Type ActiveRecord object related to this HierarchicalRule
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.Type TypeToParentTypeId
		{
			get { return Medianamik.SubsonicDALProvider.DAL.Type.FetchByID(this.ParentTypeId); }

			set { SetColumnValue("ParentTypeId", value.TypeId); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varHierarchicalRuleId,Guid varTypeId,Guid? varParentTypeId)
		{
			HierarchicalRule item = new HierarchicalRule();
			
			item.HierarchicalRuleId = varHierarchicalRuleId;
			
			item.TypeId = varTypeId;
			
			item.ParentTypeId = varParentTypeId;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varHierarchicalRuleId,Guid varTypeId,Guid? varParentTypeId)
		{
			HierarchicalRule item = new HierarchicalRule();
			
				item.HierarchicalRuleId = varHierarchicalRuleId;
			
				item.TypeId = varTypeId;
			
				item.ParentTypeId = varParentTypeId;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn HierarchicalRuleIdColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn TypeIdColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn ParentTypeIdColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string HierarchicalRuleId = @"HierarchicalRuleId";
			 public static string TypeId = @"TypeId";
			 public static string ParentTypeId = @"ParentTypeId";
						
		}

		#endregion
		
		
		
	}

}

